*** This code produces descriptive statistics and other information mentioned throught the text 	***
*** For Tuttnauer & Wegmann in APSR 																***
*** "Voting for Votes: Opposition Parties’ Legislative Activity and Electoral Outcomes"				***

*** Using the vote-level dataset for general information on the underlying data
use TW_votelevel_data.dta, clear

** General information

* Number of party-term observations and number of legislative party-votes
tab partyterm_unique

* Number and list of countries
tab country_u
tab country

* Number of elections
tab election_unique

* Number of unique legislative votes
tab vote_unique


*** Using the party-term-level dataset for more analysis-related information
use TW_partyterm_data.dta, clear

** Ranges for variables mentioned in the data section
sum vote_share, detail /* also used to establish the median of the variable */
sum conflict_rate /* also used to establish the stadard deviation of the variable */
bysort country: sum conflict_rate
bysort country: sum ppop
sum ideo_gap, detail /* also used to establish the median of the variable */

** Calculating the intra-country range of conflict rate
bysort country: egen max_conflict = max(conflict_rate)
bysort country: egen min_conflict = min(conflict_rate)
bysort country: gen range_conflict = max_conflict - min_conflict
bysort country: sum range_conflict
drop max_conflict min_conflict range_conflict

** Interpreting Figure 1: Median vote share in previous and upcoming elections
sum next_voteshare, detail
sum vote_share, detail

** Interpreting Figure 2: Conditional effect of conflict on vote share in t+1 by opposition powers
* How many cases fall in the range of PPOP (0.426-0.603) in which conflict has a significant effect?
sum ppop if ppop<.603 /* 89 cases */
di 89/169 /* which are 52.6% of the cases */

** Footnote 12 - correlation between seat share and vote share
pwcorr vote_share party_size, sig obs

** Interpreting Figure 4: Conditional effect of conflict on vote share in t+1 by ideological distance
* How many cases fall in the range of PPOP (0.426-0.603) in which conflict has a significant effect?
sum ideo_gap if ideo_gap<.42 /* 130 cases */
di 130/169 /* which are 77% of the cases */

** Robustness section: correlation between each party's vote share change and all other vote-share change
gen vote_change = next_voteshare - vote_share
bysort cabinet_id: egen all_change = total(vote_change)
gen other_change = all_change - vote_change
pwcorr vote_change other_change, sig obs
drop *change

** Correlation between conflict rate and ideological distance
pwcorr conflict_rate ideo_gap, sig obs

** Table A.1: Descriptive statistics of conflict rate, by country
bysort country: sum conflict_rate

** Table A.2: Descriptive statistics of independent and control variables
sum vote_share ideo_gap ppop gdpgrowth early_election enps_cab cabinet_size enps federal proportional ///
	frequency full_record
